package mess;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.List;

public class LeeCode_777_Failed {
    public static void main(String[] args) {
        System.out.println(canTransform("XXXXLX", "LXXXXX"));
    }
    private static boolean canTransform(String start, String end) {
        int len = start.length();
        StringBuilder startBuilder = new StringBuilder();
        startBuilder.append(start);
        if (start.length() != end.length()) {
            return false;
        }
        for (int m = 0; m < len; m++) {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < len - 1; i++) {
                if (start.charAt(i) == start.charAt(i + 1))
                    continue;
                if ((start.charAt(i) == 'X' && start.charAt(i + 1) == 'L')
                        || (start.charAt(i) == 'R' && start.charAt(i + 1) == 'X')){
                    list.add(i);
                }
            }
            System.out.println(startBuilder);
            System.out.println(list);

            outloop:for (int i = 0; i < len; i++) {
                if (startBuilder.charAt(i) != end.charAt(i)){
                    for (int j = 0; j < list.size(); j++) {
                        if (i == list.get(j)){
                            //交换
                            char tempC = startBuilder.charAt(i);
                            startBuilder.replace(i, i + 1, startBuilder.charAt(i + 1) + "");
                            startBuilder.replace(i + 1, i + 2, tempC + "");
                            System.out.println(startBuilder);
                            if (startBuilder.charAt(i) == end.charAt(i))
                                continue outloop;
                        }
                    }
                }
            }
        }
        return false;
    }
}
